﻿/*-----------------------------------------------
// File: FirstRoundEnterState.cs
// Description: 
// Author: Shaobing	492057342@qq.com
-----------------------------------------------*/
using UnityEngine;
using System.Collections;

namespace Battle.View
{
    public class FirstRoundEnterState : RoundEnterState
    {
        protected BattleViewFirstCtrl firstViewCtrl {
            get { return viewCtrl as BattleViewFirstCtrl; }
        }
        public FirstRoundEnterState(BattleRoundState state, BattleRoundCtrl ctrl) : base(state, ctrl) { }

        public override void Enter()
        {
            viewCtrl.hasRoundFight = false;
            viewCtrl.ResetCurrentShowBC();
            viewCtrl.isCanRoundOver = false;

            if (viewCtrl.curRunningCamp == BattleCamp.Attacker)
            {
                if (!firstViewCtrl.isFirstDialogShowed)
                {
                    if (firstViewCtrl.dialogEnum == BattleViewFirstCtrl.FirstBattleDialogEnum._998)
                    {
                        ManagerController.Instance.storyManager.dialogManager.Show("dialog_998", FirstBattleDialogEnd);
                        firstViewCtrl.dialogEnum = BattleViewFirstCtrl.FirstBattleDialogEnum._999;
                        FirstCheckPointUtil.CheckPoint(EnterGameCheckPointEnum.EnterGameBattleBegin);
                    }
                    else if (firstViewCtrl.dialogEnum == BattleViewFirstCtrl.FirstBattleDialogEnum._999)
                    {
                        ManagerController.Instance.storyManager.dialogManager.Show("dialog_999", AskNewRound);
                        firstViewCtrl.dialogEnum = BattleViewFirstCtrl.FirstBattleDialogEnum.Done;
                        if (BattleViewCtrl.GetInstance().isAuto)
                        {
                            BattleViewCtrl.GetInstance().SendAuto(false);
                        }
                    }
                    else if (firstViewCtrl.dialogEnum == BattleViewFirstCtrl.FirstBattleDialogEnum.Done) {
                        firstViewCtrl.isFirstDialogShowed = true;
                        AskNewRound();
                    }
                }
                else {
                    AskNewRound();
                }
            }
            else {
                BattleManager.Instance.battleEngine.compute.data.defender.angerNum = BattleManager.Instance.battleEngine.compute.data.defender.maxAngerNum;
                BattleViewCtrl.GetInstance().SetAngerNum(BattleViewCtrl.GetInstance().GetAngerMax(BattleCamp.Defender), BattleCamp.Defender);
               
                AskNewRound();
            }
        }

        void FirstBattleDialogEnd()
        {
            FirstCheckPointUtil.CheckPoint(EnterGameCheckPointEnum.EnterGameBattleBeginTalkEnd);
            AskNewRound();
        }

        public override void NewRoundCallback()
        {
            if (ctrl.currentCamp == BattleCamp.Attacker)
            {
                BattleManager.Instance.battlePanel.EnterOurTurn();
                if (!firstViewCtrl.isFirstUltimateCanCast) {
                    BattleManager.Instance.battlePanel.HideAngerBar();
                }
            }
            else {
                BattleManager.Instance.battlePanel.LeaveOutTurn();
            }
            ctrl.SwitchState(BattleRoundState.RoundWaitState);
        }

    }
}